<template>
  <view>
    <web-view :src="url" @message="onMessage"></web-view>
  </view>
</template>

<script>
import api from "@/api/api.js";
import tip from "@/utils/tip.js";
export default {
  data() {
    return {
      url: "",
    };
  },
  onLoad(item) {
    // this.url = item.url;
  },
  onShow() {
    this.getUrl();
  },
  methods: {
    async getUrl() {
      let res = await api.tokenUrl({
        query: {},
        method: "get",
      });

      if (res.code == 0) {
        this.url = res.data;
      } else {
        tip.defaults(res.msg);
      }
    },
    onMessage(event) {
      // 关闭Webview
      if (event.detail.data[0].action == "closeWebview") {
        const currentWebview = this.$scope.$getAppWebview();
        currentWebview.children()[0].clear();
        uni.navigateBack();
      }
    },
  },
};
</script>

<style>
</style>
